import {login} from "@/api/api";
import Session from "@/utils/storage";

export default ({
    state: {
        phone: '',
        token: '',
    },
    mutations: {
        dologinPhoneSet: (state, phone) => {
            state.phone = phone;
        },
        dologinTokenSet: (state, token) => {
            state.token = token;
        },
    },
    actions: {
        doLogin(context, params) {
            return new Promise((resolve, reject) => {
                login(params).then(res => {
                    if (res.data.code === 200) {
                        context.commit("dologinPhoneSet", res.data.data.phone)
                        Session.set("token", res.data.data.token)
                        context.commit("dologinTokenSet", res.data.data.token)
                    }
                    resolve(res);
                }).catch(err => {
                    reject(err)
                })
            })
        }
    },

})